<?php
foreach ($_COOKIE as $key => $value) {
    setcookie($key, 'off', time() - 7200);
}
foreach ($_POST as $key => $value)
    setcookie($key, $value, time() + 5000000000);

include 'header.php';

// TODO: Sort by values... in medium(!) report
// TODO: Separate report for All Tier-3 owners. To See who and how much...
// TODO: Names as quick links on top
// TODO: Add Closed by Priority, Resolution reason, closed by Products.
// TODO: Add Graphs (by Google Charts API) scalable, big, yearly, custsat.
// TODO: Add Graph which shows dynamic of opened/closed tickets;
// TODO: Add multiple report views(horizotal/vertical ).
// HOW MUCH SRS are opened per day for REPORTING?
// Current load table
//
// returns IP
function getIP() {
    if (isset($_SERVER['HTTP_X_REAL_IP']))
        return $_SERVER['HTTP_X_REAL_IP'];
    return $_SERVER['REMOTE_ADDR'];
}

//getIP();

function get_date($date1) {
    if ($date1 == '')
        return 0;
    if (strpos($date1, '.')) {       // 02.03.2009 12:59
        $date1 = explode(' ', $date1);
        $date2 = explode('.', $date1[0]);
        $date1 = explode(':', $date1[1]);
        $date1 = mktime($date1[0], $date1[1], 0, $date2[0], $date2[1], $date2[2]);
    } else {                            // 1/15/2009 02:38:19 PM
        $date3 = explode(' ', $date1);
        $date2 = explode('/', $date3[0]);
        $date1 = explode(':', $date3[1]);
        if ($date3[2] == 'PM')
            $date1[0] += 12;
        $date1 = mktime($date1[0], $date1[1], $date1[2], $date2[0], $date2[1], $date2[2]);
    }
    return $date1;
}

require 'dbconnect.php';

$result = mysql_query('select max(modified) as max from srs');
$res = mysql_fetch_assoc($result);
echo '<p align="center">ACTUAL ON: ' . date("r", $res['max']) . '</p>';
mysql_free_result($result);

echo $_POST['_since'] . ' - ' . $_POST['_till'] . '<br>';

$from = strtotime($_POST['_since']);
$till = strtotime($_POST['_till']);

// getting list of owner ids as a string
foreach ($_POST as $key => $value)
    if (substr($key, 0, 1) <> '_')
        $ids = $ids . str_replace("_", "", $key) . ',';
$ids = substr($ids, 0, strlen($ids) - 1);      // TODO replace with cut_string function...
$ids = addslashes($ids);

// system log

if (getIP() <> '::1' and getIP() <> '192.168.83.96') {
    $query = 'insert into log values(' . time() . ',\'' . addslashes(getIP()) . '\',\'' . addslashes(gethostbyaddr(getIP())) . '\',' . addslashes($from) . ',' . addslashes($till) . ',\'' . $_POST['_details'] . '\',\'' . $ids . '\')';
    mysql_query($query) or die('system log internal error, please call Batman');
}

$cs_threshold = 3.99; //Customer Satisfaction threshold, red color;
$tier3_threshold = 40;
$kcs_threshold = 50;
$topmarks_threshold = 80;
if ($_POST['_period'] == 'on')
    echo '<a href="#period"><li>SR Closure Rate for a period</a><br>';
if ($_POST['_current'] == 'on')
    echo '<a href="#current"><li>Current SRs</a><br>';
echo '<a href="index.php">Back to root page</a><br>';

if ($_POST['_products'] == 'on') {
    require 'products.php';
}
if ($_POST['_period'] == 'on') {
    require 'period.php';
    require 'buildlowreport.php';
}  
if ($_POST['_period'] == 'high') {
    require 'period.php';
    require 'prostynya.php'; 
    require 'report.php'; 
}
if ($_POST['_monthly'] == 'on') {
    require 'monthly.php';
    require 'charts.php';
}
if ($_POST['_reason'] == 'on') {
    //require 'srsubstatus.php';
    require 'reportbysubstatus.php';
}
if ($_POST['_current'] == 'on') {
    require 'current.php';
    require 'currentreport.php';
}

echo '<br><a href="index.php">Back to root page</a><br>';
//echo '<img alt="Yepp, these guys...."  src="img\db.png" width="115" height="165">';

// targets for current srs
// $TargetArr(
// New   1=1 2=2 3=5 4=7
// T1    1=1 2=2 3=5 4=7
// T2    1=1 2=2 3=5 4=7
// T3    1=1 2=4 3=5 4=7
// Order 1=5 2=10 3=30 4=60
// ER    1=2 2=10 3=20 4=60
// PMReview 1=5 2=30 3=60 4=90
// 3rd   1=1 2=3 3=7 4=15
// IRFC  1=3 2=10 3=20 4=21
// SoftProvided 1=2 2=4 3=10 4=21
// Replied 1=2 2=4 3=10 4=21);


?>


</BODY>
</HTML>

